<template>
    <div class="city-box">
        <city-header></city-header>
        <city-search :cities="cities"></city-search>
        <city-list
          :hot="hot"
          :cities="cities"
          :letter="letter"
        ></city-list>
        <alphabet :cities="cities" @change="changeLetter" ></alphabet>
    </div>
</template>

<script>
import axios from 'axios'
import CityHeader from '@/pages/city/components/CityHeader.vue'
import CitySearch from '@/pages/city/components/CitySearch.vue'
import CityList from '@/pages/city/components/CityList.vue'
import Alphabet from '@/pages/city/components/Alphabet.vue'
export default {
  name: 'City',
  data () {
    return {
      hot: [],
      cities: {},
      letter: ''
    }
  },
  components: {
    CityHeader,
    CitySearch,
    CityList,
    Alphabet
  },
  methods: {
    getCityInfo: function () {
      axios.get('/api/city.json')
        .then(this.getCityInfoSucc)
        .catch(function (error) {
          console.log(error)
        })
    },
    getCityInfoSucc: function (res) {
      res = res.data
      if (res.ret && res.data) {
        console.log('city data ok')
        const data = res.data
        // console.log(data)
        this.hot = data.hotCities
        this.cities = data.cities
      }
    },
    changeLetter: function (letter) {
      // console.log(letter)
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style lang="stylus" scoped>

</style>
